//
//  MyMovieCell.m
//  UI豆瓣2
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MyMovieCell.h"
#import "Movie.h"
@implementation MyMovieCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createMyMovie];
    }
    return self;
}

- (void)createMyMovie{
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 337, 50)];
    [self.contentView addSubview:self.title];
    [_title release];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(330, 10, 24, 24);
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];
    
}

- (void)buttonAction:(UIButton *)btn{
    
    //如果当前Movie没被勾选
    if (self.movie.selected) {
        //2.点击按钮的时候加判断
        [self.button setBackgroundImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
    }else
    {
        [self.button setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
    }
    self.movie.selected = !self.movie.selected;
    [self.myMovieDele info:self.movie indexPath:self.indexPath];

    
}

- (void)setMovie:(Movie *)movie{
    if (_movie != movie) {
        [_movie release];
        _movie = [movie retain];
    }
    
    self.title.text = self.movie.movieName;
    
    //上拉下拉时cell会重用,所以在赋值时需要判断
    [self.button setBackgroundImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
    if (_movie.selected) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
    }
}

@end
